home *** CD-ROM | disk | FTP | other *** search
Text File | 1993-01-25 | 2.2 KB | 110 lines | [TEXT/ALFA] |
- #=============================================================================
- # 'Fill' routines.
- #=============================================================================
-
- proc fillParagraph {} {
- set pos [getPos]
- set start [paraStart $pos]
- set finish [paraFinish $pos]
- goto $start
- set text [fillText $start $finish]
- replaceText $start $finish $text "\r"
- goto $pos
- }
-
- proc fillRegion {} {
- set start [lineStart [getPos]]
- set finish [selEnd]
- goto $start
- set text [fillText $start $finish]
- replaceText $start $finish $text "\r"
- }
-
- proc wrapParagraph {} {
- set pos [getPos]
- set start [paraStart $pos]
- set finish [paraFinish $pos]
- goto $start
- wrapText $start $finish
- goto $pos
- }
-
- proc wrapRegion {} {
- set start [lineStart [getPos]]
- set finish [selEnd]
- if {$start == $finish} {
- set finish [maxPos]
- }
- wrapText $start $finish
- }
-
- proc paraStart {pos} {
- set res [search -n -f 0 -r 1 {^[ \t]*$} $pos 0]
- if {![string length $res]} {return 0}
- return [nextLineStart [lindex $res 0]]
- }
-
-
- proc paraFinish {pos} {
- set end [maxPos]
- set res [search -n -f 1 -r 1 {^[ \t]*$} $pos $end]
- if {![string length $res]} {return $end}
- return [lindex $res 0]
- }
-
-
- proc oldParaStart {pos} {
- set pos [lineStart $pos]
- while {$pos > 0} {
- set back [lineStart [expr $pos-1]]
- if {$back < 0} {return 0}
- if {[regexp "^\[ \t\]*\r$" [getText $back $pos]]} {return $pos}
- set pos $back
- }
- return 0
- }
-
-
- proc oldParaFinish {pos} {
- set end [maxPos]
- while {$pos < $end} {
- set next [nextLineStart $pos]
- if {$pos == "-1"} {return $end}
- if {[regexp "^\[ \t\]*\r$" [getText $pos $next]]} {return $pos}
- set pos $next
- }
- return $end
- }
-
-
- # Remove text from window, transform, and insert back into window.
- proc fillText {from to} {
- # Get The text
- set text [getText $from $to]
-
- # Remove duplicated white space, carriage returns.
- regsub -all "\[ \t\r\]+" $text " " text
-
- # Insert left margins and carriage returns, doesn't end with a carriage return.
- return [breakIntoLines $text]
- }
-
- proc lineToParagraph {} {
- global fillColumn
- global leftFillColumn
- saveVars
- set fillColumn 10000
- set leftFillColumn 0
- fillRegion
- restoreVars}
-
- proc paragraphToLine {} {
- global fillColumn
- global leftFillColumn
- saveVars
- set fillColumn 75
- set leftFillColumn 0
- fillRegion
- restoreVars}
-
-